<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>document</title>
</head>
<body>
  <script src="./lodash.min.js"></script>
  <script>
      const obj = {
        uname: 'kunkun',
        age: '18',
        hobbit: ['唱', '跳', 'rap', '打篮球'],
        student: {
          uname: '李四',
          sex: '男',
          hobbit: ['学习', '摸鱼', '查资料'],
        },
      }
      
      let obj2 = {}
      // 封装递归方法
      function deepClone(odlobj,newobj){
        // 遍历对象
        for(let k in odlobj){
          // 判断当前属性的数据类型，如果为复杂数据类型则会进入多层循环
          if(odlobj[k] instanceof Array){
            // 创建一个新的数组空间
            newobj[k] = []
            // 递归函数，进入多层循环
            deepClone(odlobj[k],newobj[k])
          }else if(odlobj[k] instanceof Object){
            newobj[k] = {}
            deepClone(odlobj[k],newobj[k])
          } else{
            // 如果是简单数据类型，则直接赋值，当遍历完成后，该层循环回到上一层
              newobj[k] = odlobj[k]
          }
        }
      }
      deepClone(obj,obj2)

      // obj2 =  _.cloneDeep(obj)
      console.log(obj);
      console.log(obj2);

  </script>
</body>
</html>